package de.tum.in.eist.poll.server;



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Sql {
	Connection con;
	Statement st;
	
	public Sql(String server, String user, String pw) throws ClassNotFoundException, SQLException{
			//Register the JDBC driver for MySQL.
			 Class.forName("com.mysql.jdbc.Driver");
			 con = DriverManager.getConnection(server,user, pw);
	}
	
	public void executeUpdate(String query) throws SQLException{
			st = con.createStatement(); 
			st.executeUpdate(query);
	}
	
	public ResultSet executeQuerry(String query) throws SQLException{
			st = con.createStatement(
					ResultSet.TYPE_SCROLL_INSENSITIVE,
					ResultSet.CONCUR_READ_ONLY
					);
			return st.executeQuery(query);
	}
	
	public void closeConnection(){
		try {
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
